#include "ThreadPool.h"

#include <unistd.h>
#include <iostream>
#include <mutex>

using namespace std;
using namespace util;

int sum = 0;
mutex mtx;

class MyTask : public Task
{
public:
    MyTask()
    {

    }

    ~MyTask() override
    {
        
    }
    
    void run() override
    {
        while (sum < 10000000)
        {
            mtx.lock();
            ++sum;
            //cout << sum << endl;
            mtx.unlock();
        }
    }
};

void work()
{
    util::ThreadPool pool(1, 1, 16);
    MyTask task;
    pool.start(&task);
    pool.run();
}

int main()
{
    auto start = std::chrono::high_resolution_clock::now();
    
    work();

    auto end = std::chrono::high_resolution_clock::now();
    auto duration = std::chrono::duration_cast<std::chrono::milliseconds>(end - start);
    //auto duration = std::chrono::duration_cast<std::chrono::seconds>(end - start);


    std::cout << "expired: " << duration.count() << " ms" << std::endl;
    //std::cout << "expired:" << duration.count() << " s" << std::endl;

	return 0;
} 